#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int maxProductPath(vector<vector<int>>& grid) {
    int n = grid.size(), m = grid[0].size();
    const int mod = 1e9 + 7;
    vector<vector<long long>> f(n + 1, vector<long long>(m + 1));
    vector<vector<long long>> g(n + 1, vector<long long>(m + 1));
    f[1][1] = g[1][1] = grid[0][0];
    for (int i = 2; i <= m; i++)   f[1][i] = g[1][i] = f[1][i - 1] * grid[0][i - 1];
    for (int i = 2; i <= n; i++)   f[i][1] = g[i][1] = f[i - 1][1] * grid[i - 1][0];
    for (int i = 2; i <= n; i++)
        for (int j = 2; j <= m; j++)
        {
            if (grid[i - 1][j - 1] >= 0)
            {
                f[i][j] = max(f[i - 1][j], f[i][j - 1]) * grid[i - 1][j - 1];
                g[i][j] = min(g[i - 1][j], g[i][j - 1]) * grid[i - 1][j - 1];
            }
            else
            {
                f[i][j] = min(g[i - 1][j], g[i][j - 1]) * grid[i - 1][j - 1];
                g[i][j] = max(f[i - 1][j], f[i][j - 1]) * grid[i - 1][j - 1];
            }
        }

    if (f[n][m] < 0)  return -1;
    return f[n][m] % mod;
}

int main()
{
    vector<vector<int>> vv = { {4,3} };
    maxProductPath(vv);
    return 0;
}